






*import delimited "C:\Users\xisaka\ShareFile\Personal Folders\AidData\GeoCoded_China_Data_Merged_Files\GeoCoded_China_Data_Merged_Files\all_flow_classes.csv", clear 
*save "C:\Users\xisaka\ShareFile\Personal Folders\AidData\GeoCoded_China_Data_Merged_Files\GeoCoded_China_Data_Merged_Files\all_flow_classes.dta", replace

use "C:\Users\xisaka\ShareFile\Personal Folders\AidData\GeoCoded_China_Data_Merged_Files\GeoCoded_China_Data_Merged_Files\all_flow_classes.dta", clear


*all recipient countries in the dataset
tab all_recipients
codebook project_id						
codebook project_location_id		  	

	
***RESTRICT TO PROJECTS WITH PRECISE GEOCODES

tab precision_code
keep if precision_code<3

tab recipient_oecd_name
codebook project_id						
codebook project_location_id		  	


***RESTRICT TO THOSE WITH INFO ON STARTDATE

drop if start_actual==""

tab all_recipients
codebook project_id					
codebook project_location_id		  	

			   
*FIX DATE VARIABLES

gen startyear=substr(start_actual, 1,4)			
destring startyear, replace
sum startyear

gen endyear=substr(end_actual, 1,4)
destring endyear, replace
sum endyear

tab recipient_oecd_name


*save "C:\Users\xisaka\Dropbox\Projekt\Gendergap\Aid_China\all new chinese projects global.dta", replace		



********RESTRICT TO SSA COUNTRIES SURVEYED BY THE AFROBAROMETER

tab recipient_oecd_nam		

*create a dummy for being a country part of the afrobarometer estimation sample
gen afrobarestsample =cond(recipient_oecd_name=="Benin" 				| recipient_oecd_name=="Botswana" 	| recipient_oecd_name=="Burundi"	| recipient_oecd_name=="Cameroon" 		| recipient_oecd_name=="Cape Verde" | recipient_oecd_name=="Cote D'Ivoire" ///
| recipient_oecd_name=="Ethiopia" 	| recipient_oecd_name=="Gabon" 		| recipient_oecd_name=="Ghana"  	| recipient_oecd_name=="Guinea"		| recipient_oecd_name=="Kenya" 			| recipient_oecd_name=="Lesotho" ///
| recipient_oecd_name=="Liberia" 	| recipient_oecd_name=="Madagascar" | recipient_oecd_name=="Malawi" 	| recipient_oecd_name=="Mali" 		| recipient_oecd_name=="Mauritius"  	| recipient_oecd_name=="Mozambique" ///
| recipient_oecd_name=="Namibia" 	| recipient_oecd_name=="Niger" 		| recipient_oecd_name=="Nigeria" 	| recipient_oecd_name=="Senegal" 	| recipient_oecd_name=="Sierra Leone" 	| recipient_oecd_name=="South Africa" ///
| recipient_oecd_name=="South Sudan" | recipient_oecd_name=="Sudan" 	| recipient_oecd_name=="Tanzania" 	| recipient_oecd_name=="Togo" 		| recipient_oecd_name=="Uganda" 		| recipient_oecd_name=="Zambia" | recipient_oecd_name=="Zimbabwe",1,0) 	

*NOTE: in afrobar sample but not in china aid: Burkina Faso, Swaziland (Eswatini), sao tome and principe, the gambia 
*recieve aid from china but is not in afrobar: for instance rwanda  projects in rwanda likely to be connected to afrobar respondents in eg burundi

tab recipient_oecd_name if afrobarestsample==0
replace afrobarestsample=1 if recipient_oecd_name=="Africa, regional; Kenya"
replace afrobarestsample=1 if recipient_oecd_name=="Africa, regional; Zimbabwe"

keep if afrobarestsample==1	

tab all_recipients
codebook project_id					
codebook project_location_id		  	

sort project_id	

bysort recipient_oecd_name: tab project_location_id


/*benchmark estimation sample is restricted to include the 11 Afrobarometer countries with observations connected to both ongoing and future Chinese development projects, i.e. the countries that have both a post- and a pre-treatment group of respondents (see Section 3.1). These are: Benin, Botswana, Cape Verde, Kenya, Liberia, Madagascar, Malawi,  Mali,  Namibia,  Nigeria  and Senegal.*/

gen 	estsample	=cond((recipient_oecd_name=="Benin" | recipient_oecd_name=="Botswana" | recipient_oecd_name=="Cape Verde" | recipient_oecd_name=="Kenya" | recipient_oecd_name=="Liberia" | recipient_oecd_name=="Madagascar" | recipient_oecd_name=="Malawi" | recipient_oecd_name=="Mali" | recipient_oecd_name=="Namibia" | recipient_oecd_name=="Nigeria" | recipient_oecd_name=="Senegal") ,1,0)

codebook project_id			if estsample==1				/*71 projects */
codebook project_location_id	if estsample==1		  	/*125 project locations in estimation sample*/



gen antalprojlocations=1 	
replace recipient_oecd_name="Kenya" if recipient_oecd_name=="Africa, regional; Kenya"
replace recipient_oecd_name="Zimbabwe" if recipient_oecd_name=="Africa, regional; Zimbabwe"
preserve
	collapse (rawsum) antalprojlocations, by(recipient_oecd_name)
	gen 	estsample	=cond((recipient_oecd_name=="Benin" | recipient_oecd_name=="Botswana" | recipient_oecd_name=="Cape Verde" | recipient_oecd_name=="Kenya" | recipient_oecd_name=="Liberia" | recipient_oecd_name=="Madagascar" | recipient_oecd_name=="Malawi" | recipient_oecd_name=="Mali" | recipient_oecd_name=="Namibia" | recipient_oecd_name=="Nigeria" | recipient_oecd_name=="Senegal") ,1,0)
	sum antalprojlocations if estsample==1			//on average 11.5 projects per country in estimation sample, min 2 in cape verde, max 42 in kenya
	tab recipient_oecd_name if antalprojlocations==2
	tab recipient_oecd_name if antalprojlocations==42
	codebook antalprojlocations if estsample==1	
	*bysort recipient_oecd_name: tab antalprojlocations
restore


	
save "C:\Users\xisaka\ShareFile\Personal Folders\AidData\\all chinese projects to afrobar countries.dta", replace		

	


		
********************RESTRICT TO ODA-LIKE FLOWS
	   
			   		  			   

gen ODA_like = 1 if flow_class=="ODA-like" 
replace ODA_like=0 if ODA_like==.

gen OOF_like = 1 if flow_class=="OOF-like" 
replace OOF_like=0 if OOF_like==.

gen vague = 1 if flow_class=="Vague (Official Finance)" 
replace vague=0 if vague==.

keep if ODA_like==1							   
			   
codebook project_id						
codebook project_location_id		  	

	
save "C:\Users\xisaka\ShareFile\Personal Folders\AidData\\ODA_like chinese projects to afrobar countries.dta", replace		




		 
		





